﻿using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

using PortalIntranet.DatabaseComponents.Administracao;
using PortalIntranet.DatabaseComponents.Comun;
using System.Data.Entity.ModelConfiguration;

namespace PortalIntranet.DatabaseComponents.Seguranca
{
	[Serializable]
	[Table("Usuarios")]
	public class Usuario : Entidade
	{
		public Usuario()
		{
		}

		[Required, MaxLength(50)]
		public string Nome { get; set; }

		[Required, MaxLength(30)]
		public string Email { get; set; }

		[Required, MaxLength(30)]
		public string Login { get; set; }

		[MaxLength(100)]
		public string Senha { get; set; }

		[MaxLength(30)]
		public string Telefone { get; set; }

		[MaxLength(30)]
		public string Celular { get; set; }

		public DateTime? UltimoAcesso { get; set; }

		public DateTime? Aniversario { get; set; }

		[MaxLength(50)]
		public string Foto { get; set; }

		[MaxLength(50)]
		public string Avatar { get; set; }

		#region Departamento
		public int DepartamentoId { get; set; }

		public virtual Departamento Departamento { get; set; }
		#endregion

		#region Grupoo
		public int GrupoId { get; set; }

		public virtual Grupo Grupo { get; set; }
		#endregion
	}

	internal class UsuarioConfiguration : EntityTypeConfiguration<Usuario>
	{
		internal UsuarioConfiguration()
		{
			this.HasRequired(b => b.Departamento)
				.WithMany(i => i.Usuarios)
				.HasForeignKey(b => b.DepartamentoId);

			this.HasRequired(b => b.Grupo)
				.WithMany(i => i.Usuarios)
				.HasForeignKey(b => b.GrupoId);
		}
	}
}
